unit F_Configuracion;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, IniFiles, JvExControls, JvSpeedButton,
  JvExStdCtrls, JvEdit, JvValidateEdit, JvBaseDlg, JvSelectDirectory, Mask,
  JvExMask, JvSpin;

type
  TConfiguracion = class(TForm)
    Panel1: TPanel;
    Panel_BD: TPanel;
    GB_BaseDeDatos: TGroupBox;
    L_Host: TLabel;
    E_Host: TEdit;
    PanelInferior: TPanel;
    B_Guardar: TJvSpeedButton;
    B_Cerrar: TJvSpeedButton;
    Panel_Documentos: TPanel;
    GB_Documentos: TGroupBox;
    Label_Carpeta_Inicial: TLabel;
    Label_Documento_Inicial: TLabel;
    Edit_CI: TEdit;
    Edit_DP: TEdit;
    B_MasDocumentoPresentacion: TButton;
    OpenDialog: TOpenDialog;
    JvSelectDirectory: TJvSelectDirectory;
    B_MasDocumentoCI: TButton;
    Label_Puerto: TLabel;
    JvVE_Puerto: TJvValidateEdit;
    Panel_Contrasenia: TPanel;
    GB_Contrasenia: TGroupBox;
    L_Caracteres: TLabel;
    L_Numeros: TLabel;
    JvSE_Letras: TJvSpinEdit;
    JvSE_Numeros: TJvSpinEdit;
    Panel_Spy_Printer: TPanel;
    GB_Spy_Printer: TRadioGroup;
    RB_SI: TRadioButton;
    RB_No: TRadioButton;
    Panel2: TPanel;
    GB_ConsultaDirecta: TRadioGroup;
    CD_RB_SI: TRadioButton;
    CD_RB_NO: TRadioButton;
    procedure FormCreate(Sender: TObject);
    procedure B_CerrarClick(Sender: TObject);
    procedure B_GuardarClick(Sender: TObject);
    procedure B_MasDocumentoPresentacionClick(Sender: TObject);
    procedure B_MasDocumentoCIClick(Sender: TObject);
  private
    { Private declarations }
    procedure LoadConfiguration;
    procedure SaveConfiguration;
  public
    { Public declarations }
  end;

var
  Configuracion: TConfiguracion;

implementation

uses F_Funciones;
{$R *.dfm}

procedure TConfiguracion.LoadConfiguration;
var
  MiFichero : TIniFile;
  ruta:string;
begin
  ruta:= ExtractRutaConfiguracion;
  try
    MiFichero:=TIniFile.Create(ruta);

    E_Host.Text := MiFIchero.ReadString('Conexion','Host','');
    JvVE_Puerto.Value:= MiFIchero.ReadString('Conexion','Puerto','0');
    Edit_CI.Text := MiFIchero.ReadString('Documentos','Carpeta Inicial','');
    Edit_DP.Text := MiFIchero.ReadString('Documentos','Documento Presentacion','');
    JvSE_Letras.Value:= MiFIchero.ReadInteger('Gen_Contrasenia','#Letras',0);
    JvSE_Numeros.Value:= MiFIchero.ReadInteger('Gen_Contrasenia','#Numeros',6);
    RB_SI.Checked:= MiFIchero.ReadBool('Spy_Printer','State', False);
    CD_RB_SI.Checked:= MiFIchero.ReadBool('Direct_Consult','State',False);
  finally
    MiFIchero.Free;
  end;
end;

procedure TConfiguracion.SaveConfiguration;
var
  MiFichero : TIniFile;
  ruta:string;
begin
  ruta:= ExtractRutaConfiguracion;
  try
    MiFichero:=TIniFile.Create(ruta);

    MiFIchero.WriteString('Conexion','Host', E_Host.Text);
    MiFIchero.WriteString('Conexion','Puerto', JvVE_Puerto.Value);
    MiFIchero.WriteString('Documentos','Carpeta Inicial',Edit_CI.Text);
    MiFIchero.WriteString('Documentos','Documento Presentacion',Edit_DP.Text);
    MiFIchero.WriteString('Gen_Contrasenia','#Letras', JvSE_Letras.Text);
    MiFIchero.WriteString('Gen_Contrasenia','#Numeros',JvSE_Numeros.Text);
    MiFIchero.WriteBool('Spy_Printer','State',RB_SI.Checked);
    MiFIchero.WriteBool('Direct_Consult','State',CD_RB_SI.Checked);

  finally
    MiFIchero.Free;
  end;
end;


procedure TConfiguracion.FormCreate(Sender: TObject);
begin
  LoadConfiguration;
end;

procedure TConfiguracion.B_CerrarClick(Sender: TObject);
begin
  Close;
end;

procedure TConfiguracion.B_GuardarClick(Sender: TObject);
begin
  SaveConfiguration;
  Close;
end;

procedure TConfiguracion.B_MasDocumentoPresentacionClick(Sender: TObject);
begin
  if (OpenDialog.Execute) then
    begin
      Edit_DP.Text:= OpenDialog.FileName;
    end;
end;

procedure TConfiguracion.B_MasDocumentoCIClick(Sender: TObject);
begin
  if (JvSelectDirectory.Execute) then
    begin
      Edit_CI.Text:= JvSelectDirectory.Directory;
    end;
end;

end.
